/**
 * @File    : oddEvenList.cpp
 * @Brief   : 奇偶链表
 * @Link    : https://leetcode-cn.com/problems/odd-even-linked-list/
 * @Author  : Wei Li
 * @Date    : 2021-07-30
*/

#include <iostream>

// Definition for singly-linked list
struct ListNode
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution
{
public:
    ListNode *oddEvenList(ListNode *head)
    {
        if (head == nullptr)
        {
            return head;
        }
        ListNode *evenHead = head->next;
        ListNode *odd = head;
        ListNode *even = evenHead;
        while (even != nullptr && even->next != nullptr)
        {
            odd->next = even->next;
            odd = odd->next;
            even->next = odd->next;
            even = even->next;
        }
        odd->next = evenHead;
        return head;
    }
};

int main(int argc, char **argv)
{

    return 0;
}
